import namespace from "../namespace";

class CommandAdd extends namespace.command.Command {
  constructor(canvas, figure, x, y) {
    super();
    this.canvas = canvas;
    this.figure = figure;
    this.x = x;
    this.y = y;
  }

  execute() {
    this.x && this.figure.setPosition(this.x, this.y);
    this.canvas.addFigure(this.figure);
  }

  canExecute() {
    return this.figure.getCanvas() == null;
  }

  redo() {
    this.execute();
  }

  undo() {
    this.canvas.removeFigure(this.figure);
  }
}

namespace.command.CommandAdd = CommandAdd;
